package com.compiler.model;

import java.util.ArrayList;

import com.annotation.MvpModel;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;


/**
 * Created by huilin on 2017/12/9.
 */

public class MvpModelType {

    TypeElement mTypeElement;
    public ArrayList<ExecutableElement> mMethods;
    public String mClassName;
    public String mPackName;
    public MvpServiceType mvpServiceType;

    public MvpModelType(Element element) {
        mMethods = new ArrayList<>();
        if (element.getKind() != ElementKind.INTERFACE) {
            return;
        }
        mTypeElement = (TypeElement) element;
        MvpModel annotation = mTypeElement.getAnnotation(MvpModel.class);
        mClassName = annotation.className();
        mPackName = annotation.packName();
        for (Element element1 : mTypeElement.getEnclosedElements()) {
            if (element1.getKind() == ElementKind.METHOD) {
                mMethods.add((ExecutableElement) element1);
            }
        }

    }

    public TypeMirror getModelName() {
        return mTypeElement.asType();
    }

    public String mvpClassName(){
        return mTypeElement.getEnclosingElement().getSimpleName().toString();
    }

    public String getName() {
        return mPackName + "." + mClassName;
    }
}
